<template>
	<view class="mainpadding2">
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
		</view>
		<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id">
			<view class=" titletext xiaohui nofonweight">{{item.des}}</view>
			<view class="flexleft flex_wrap">
				<view class="sanshis flexcenter margin_top2" v-for="(ite,inde) in item.images_text"
					:key="inde">
					<view class="jiaolt">
						<image :src="ite" mode="" @click="lbtpriview(inde,item.images_text)"></image>
					</view>
				</view>
			</view>
			<view class="margin_top">
				<video :src="item.video_text" object-fit="cover" class="cgtpiam" :data-id="item.id" :id="'video'+item.id" @play="playVideo"></video>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid:"",
				changePlay:false,
				videoContent:null
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.init()
		},
		methods: {
			playVideo(e){
			    let _this = this;
			    //全局变量changePlay表示正在切换。每次切换完播放等一秒在恢复，解决Android下的问题
			    if(this.changePlay) {
			        return
			    }
			    _this.changePlay = true
			    let currentId = 'video' + e.currentTarget.dataset.id;// 获取当前视频id
			    console.log("playVideo currentId ", currentId)
			    this.videoContent = uni.createVideoContext(currentId,_this).play();
			    
			    // 获取视频列表
			    let trailer = this.list.data;
			    trailer.forEach((item, index) =>{   // 获取json对象并遍历, 停止非当前视频
			        if (item.url != null && item.url.length > 0) {
			            let temp = 'video' + item.id;
			            if (temp != currentId) {
			                // 暂停其余视频
			                uni.createVideoContext(temp,_this).pause(); //暂停视频播放事件
			            }
			        }
			    })
			    setTimeout(()=>{
			        _this.changePlay = false
			    },1000)
			},
			lbtpriview(index, arr) {
				var i = arr; //获取当前页面的轮播图数据
				//uniapp预览轮播图
				uni.previewImage({
					current: index, //预览图片的下标
					urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				})
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					id: this.listid,
				}
				let url = '/api/sscl/ssJjIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style>
.cgtpiam {
		height: 360rpx;
		width: 100%;
		border-radius: 16rpx;
	}
</style>
